//
//  ProgramPopWindow.m
//  BestLearning
//
//  Created by edz on 2018/1/20.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "ProgramPopWindow.h"

@implementation ProgramPopWindow
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setup];
    }
    return self;
}
- (void)setup
{
    self.alpha = 0;
    self.hidden = YES;
    self.backgroundColor = [UIColor clearColor];
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    [window addSubview:self];

    
    self.frame = [UIScreen mainScreen].bounds;
//    [self mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.left.bottom.right.equalTo(@0);
//    }];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismiss)];
    
    
    self.backgroundView = [[UIView alloc]initWithFrame:window.bounds];
    self.backgroundView.backgroundColor = [UIColor colorWithWhite:0 alpha:.4];
    
    [self.backgroundView addGestureRecognizer:tap];
    [self addSubview:self.backgroundView];
    [self sendSubviewToBack:_backgroundView];
}
#pragma mark - Method
- (void)show
{
    self.hidden = NO;
    [UIView animateWithDuration:.2 animations:^{
        self.alpha = 1;
    }];
}

- (void)dismiss
{
    [UIView animateWithDuration:.2 animations:^{
        self.alpha = 0;
    } completion:^(BOOL finished) {
        self.hidden = YES;
    }];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
